/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../PacketCreator.h"
#include "../../server/Player.h"
#include "../../server/ObjectMoving.h"

PacketWriter* PacketCreator::showPvPMoving(Player *player, Position &pos, ObjectMoving &moving){
	pw.writeShort(MOVE_MONSTER);
	pw.writeInt(player->getID());
	pw.write(0);
	pw.write(-1);
	pw.writeInt(0);
	pw.write(0);
	pw.writeShort(pos.x);
	pw.writeShort(pos.y);
	pw.write(moving.getPacket()->getBytes(), moving.getPacket()->getLength());
	return &pw;
}

PacketWriter* PacketCreator::showPvPMovingForPlayer(Player *player, Position &start){
	pw.writeShort(MOVE_MONSTER);
	pw.writeInt(player->getID());
	pw.write(0);
	pw.write(-1);
	pw.writeInt(0);
	pw.write(0);
	pw.writeShort(start.x);
	pw.writeShort(start.y);
	pw.write(1);
	pw.write(3);
	pw.writeShort(player->getPosition().x);
	pw.writeShort(player->getPosition().y);
	pw.writeInt(0);
	pw.write(player->getStance());
	return &pw;
}

PacketWriter* PacketCreator::startPvPMobForPlayer(Player *player){
	pw.writeShort(SPAWN_MONSTER_CONTROL);
	pw.write(1);
	pw.writeInt(player->getID());
	pw.write(1); // Control status
	pw.writeInt(player->getPvPMaskMob());
	pw.writeInt(0);
	pw.writeInt(0);
	pw.writeInt(0);
	pw.write(0); // Mob's status such as frozen, stunned, and etc
	pw.writeShort(0);
	pw.write(0x88);
	pw.writeInt(0);
	pw.writeShort(0);
	pw.writeShort(player->getPosition().x);
	pw.writeShort(player->getPosition().y);
	pw.write(0x02); // 0x08 - a summon, 0x04 - flying, 0x02 - ???, 0x01 - faces right
	pw.writeShort(0);
	pw.writeShort(0);
	pw.write(-3);
	pw.write(-1);
	pw.writeInt(0);
	pw.writeInt(0);
	return &pw;
}

PacketWriter* PacketCreator::startPvPMob(Player *player){
	pw.writeShort(SPAWN_MONSTER);
	pw.writeInt(player->getID());
	pw.write(1); // Control status
	pw.writeInt(player->getPvPMaskMob());
	pw.writeLong(0);
	pw.writeInt(0);
	pw.writeShort(0);
	pw.write(0); // Mob's status such as frozen, stunned, and etc
	pw.write(0x88);
	pw.writeShort(0);
	pw.writeInt(0);
	pw.writeShort(player->getPosition().x);
	pw.writeShort(player->getPosition().y);
	pw.write(0x02); // 0x08 - a summon, 0x04 - flying, 0x02 - ???, 0x01 - faces right
	pw.writeShort(0);
	pw.writeShort(0);
	pw.write(-3);
	pw.write(-1);
	pw.writeInt(0);
	pw.writeInt(0);
	return &pw;
}

PacketWriter* PacketCreator::stopPvP(Player *player){
	return killMob(player->getID(),0);
}

PacketWriter* PacketCreator::stopPvPForPlayer(Player *player){
	return endControlMob(player->getID());
}